//
//  ThreeButtonTableViewCell.m
//  HJZWeiBo
//
//  Created by 蒋晨成 on 16/5/28.
//  Copyright © 2016年 蒋晨成. All rights reserved.
//

#import "ThreeButtonTableViewCell.h"

@implementation ThreeButtonTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
       
        self.weiboButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.weiboButton.frame = CGRectMake(0, 0, kWidth / 3, 50);
        [self.weiboButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.weiboButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        
        self.guanzhuButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.guanzhuButton.frame = CGRectMake(kWidth / 3, 0, kWidth / 3, 50);
        [self.guanzhuButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.guanzhuButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        
        self.fensiButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.fensiButton.frame = CGRectMake(kWidth * 2 / 3, 0, kWidth / 3, 50);
        [self.fensiButton
         setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.fensiButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        
        [self.contentView addSubview:_weiboButton];
        [self.contentView addSubview:_guanzhuButton];
        [self.contentView addSubview:_fensiButton];
        
        
        UILabel *weiboLabel = [[UILabel alloc] initWithFrame:CGRectMake(kWidth / 6, 30, 30, 15)];
        weiboLabel.center = CGPointMake(kWidth / 6, 40);
        weiboLabel.textAlignment = NSTextAlignmentCenter;
        weiboLabel.textColor = [UIColor grayColor];
        weiboLabel.font = [UIFont systemFontOfSize:13];
        weiboLabel.text = @"微博";
        [_weiboButton addSubview:weiboLabel];
        
        
        UILabel *guanzhuLabel = [[UILabel alloc] initWithFrame:CGRectMake(kWidth / 6, 30, 30, 15)];
        guanzhuLabel.center = CGPointMake(kWidth / 6, 40);
        guanzhuLabel.textAlignment = NSTextAlignmentCenter;
        guanzhuLabel.textColor = [UIColor grayColor];
        guanzhuLabel.font = [UIFont systemFontOfSize:13];
        guanzhuLabel.text = @"关注";
        [_guanzhuButton addSubview:guanzhuLabel];
        
        UILabel *fensiLabel = [[UILabel alloc] initWithFrame:CGRectMake(kWidth / 6, 30, 30, 15)];
        fensiLabel.center = CGPointMake(kWidth / 6, 40);
        fensiLabel.textAlignment = NSTextAlignmentCenter;
        fensiLabel.textColor = [UIColor grayColor];
        fensiLabel.font = [UIFont systemFontOfSize:13];
        fensiLabel.text = @"粉丝";
        [_fensiButton addSubview:fensiLabel];
        
    }
    return self;
}


-(void)setUser:(WeiboUser *)user {
    _user = user;
    
    [_weiboButton setTitle:user.statusesCount forState:UIControlStateNormal];
    [_fensiButton setTitle:user.followersCount forState:UIControlStateNormal];
    [_guanzhuButton setTitle:user.friendsCount forState:UIControlStateNormal];
    
}

- (void)buttonAction:(UIButton *)button {
    if ([button isEqual:_weiboButton]) {
        if ([self.delegate respondsToSelector:@selector(statusButtonAction)]) {
            [self.delegate statusButtonAction];
        }
    }else if ([button isEqual:_fensiButton]) {
        if ([self.delegate respondsToSelector:@selector(followersButtonActuon)]) {
            [self.delegate followersButtonActuon];
        }
    }else {
        if ([self.delegate respondsToSelector:@selector(friendsBUttonAction)]) {
            [self.delegate friendsBUttonAction];
        }
    }
    
}


@end
